<template>
  <div class="comment-wrap">
    <comment-textarea placeholder="说点什么" :blogId="blogId" @updateComments="updateComments"></comment-textarea>
    <comment-list :blogId="blogId" :commentList="comments"></comment-list>
  </div>
</template>

<script>
  import commentTextarea from "./commentTextarea";
  import commentList from "./commentList";
  import {getCommentList} from "../../../assets/api/getData";

  export default {
    name: "comment",
    components: {
      commentTextarea,
      commentList
    },
    props: {
      blogId: {
        type: Number,
        default: null
      },
    },
    data() {
      return {
        comments: []
      }
    },
    created() {
      this.queryComments();
    },
    methods: {
      async queryComments() {
        let res = await getCommentList(this.blogId);
        this.comments = res.data;
      },
      updateComments(){
        this.queryComments();
      }
    },
  }
</script>

<style lang="less" scoped>
  .comment-wrap {
    background-color: @color-white;
    border-radius: 4px;
    padding: 15px;
    border: 1px solid @color-border;
    margin-bottom: 20px;
  }
</style>